package com.yanqu.road.server.cmd.activity.snowgarden;

import com.yanqu.road.entity.player.CrossUserBaseInfo;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.SnowGardenProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.user.CrossUserMgr;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.utils.YanQuMessageUtils;

import java.util.ArrayList;
import java.util.List;

@Cmd(code = CrossProtocol.C_SNOW_GARDEN_GET_QUIT_UNION_USER_VISIT_RECORD,desc = "获取退出公会用户拜访记录")
public class SnowGardenGetQuitUserListCmd extends CrossCommand {

    private long userId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        userId = packet.getPlayerId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        SnowGardenProto.SnowGardenGetQuitUserReqMsg snowGardenGetQuitUserReqMsg = SnowGardenProto.SnowGardenGetQuitUserReqMsg.parseFrom(packet.getBytes());
        List<Long> userIdList = snowGardenGetQuitUserReqMsg.getUserIdList();
        int type = snowGardenGetQuitUserReqMsg.getType();

        SnowGardenProto.SnowGardenGetQuitUserRespMsg.Builder builder = SnowGardenProto.SnowGardenGetQuitUserRespMsg.newBuilder();
        builder.setType(type);
        for (long targetUserId:userIdList){
            CrossUserBaseInfo crossUserBaseInfo = CrossUserMgr.getCrossUserBaseInfo(targetUserId);
            if (crossUserBaseInfo != null){
                SnowGardenProto.SnowPlayerIdAndData.Builder snowUserInfo = SnowGardenProto.SnowPlayerIdAndData.newBuilder();
                snowUserInfo.setUserId(targetUserId);
                snowUserInfo.setUserData(PlayerBasePb.parsePlayerBaseTempMsg(crossUserBaseInfo.getUserBaseInfo()));
                builder.addData(snowUserInfo);
            }
        }
        YanQuMessage message = YanQuMessageUtils.buildMessage(GameProtocol.S_SNOW_GARDEN_GET_RECORD_USER_INFO_FROM_CROSS, builder);
        MessageHelper.sendPacket(serverId, userId, message);

    }

    @Override
    public void sendData() {

    }
}
